<?php
/**
 * 核心Db框架
 * @author sunhaoqiang(shqdev@163.com)
 * @time: 2019-08-25 16:38
*/
namespace app\item;

use script\Db;
use script\Item;

class Tizu extends Item
{
    protected $table = 'p_tizu';
    protected $item = [
        'paper_id' => '',
        'head_title' => '',
        'scores' => '',
        'question_ids' => '',
        "add_time" => '',
    ];

    public function tizuSingle($tizu)
    {
        $tizu = (array)$tizu;
        if (empty($tizu)) {
            return [];
        }
        
        $question_ids = isset($tizu['questions'])? implode(',', array_column((array)$tizu['questions'], 'question_id')): '';
        $data = [
            'paper_id' => $tizu['paper_id'],
            'head_title' => $tizu['head_title'],
            'scores' => isset($tizu['scores'])? json_encode($tizu['scores']) :'',
            // 'question_ids' => isset($tizu['scores'])? implode(',', array_keys((array)$tizu['scores'])): $question_ids,
            'question_ids' => $question_ids,
            "add_time" => date('Y-m-d H:i:s'),
        ];
        return $data;
    }
}